﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MockPrjTeam2.Common;
using System.Data.SqlClient;
using MockPrjTeam2.Entity;

namespace MockPrjTeam2.DAO
{
    public class CountyDao
    {
        public List<County> getAllCounty(int id)
        {
            const string getCountryQuery = @"SELECT CountyId,CountyName FROM County where CountryId = @CountryId";
            var listCountry = new List<County>();
            var sqlParameter = new SqlParameter[1];
            sqlParameter[0] = new SqlParameter { ParameterName = "@CountryId", Value = id };
            using (var helper = new SqlHelper())
            {
                var reader = helper.ExecuteReader(getCountryQuery, sqlParameter);
                while (reader.Read())
                {
                    var county = new County(reader.GetInt32(0), reader.GetString(1));
                    listCountry.Add(county);
                }
            }
            return listCountry;
        }
    }
}